package com.example.jaden.myapplication;

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.RadioGroup;

import androidx.annotation.RequiresApi;

public class RunActivity extends android.app.Activity {

    private RadioGroup radioGroup;
    private Button button;
    private ImageButton MusicButton;
    private OnClickListener listener = new OnClickListener() {

        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.chuquan:
                    // 获得所选择的拳
                    int id = radioGroup.getCheckedRadioButtonId();
                    int quan = 0;
                    // 根据不同的选择 给一个整型值赋值 石头1 剪刀2 布3
                    switch (id) {
                        case R.id.Stone:
                            quan = getResources().getInteger(R.integer.one);
                            break;
                        case R.id.Scissors:
                            quan = getResources().getInteger(R.integer.two);
                            break;
                        case R.id.Cloth:
                            quan = getResources().getInteger(R.integer.three);
                            break;

                        default:
                            break;
                    }
                    // 启动结果页面 并传值
                    Intent intent = new Intent();
                    intent.setClass(RunActivity.this, ResultActivity.class);
                    intent.putExtra("quan", quan);
                    startActivity(intent);
                    break;

                default:
                    break;
            }

        }
    };

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.run_activity);
        radioGroup = findViewById(R.id.radiogroupe);
        button = findViewById(R.id.chuquan);
        button.setOnClickListener(listener);
     //音乐播放按钮,实现点击切换显示图片
        MusicButton=findViewById(R.id.playBtn);
        MusicButton.setOnClickListener(new OnClickListener() {
            @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
            @Override
            public void onClick(View view) {
                if (MusicService.isplay==false){
                    startService(new Intent(RunActivity.this, MusicService.class));
                    ((ImageButton) view).setImageDrawable(getResources().getDrawable(R.drawable.start, null));
            } else {
                stopService(new Intent(RunActivity.this, MusicService.class));
                ((ImageButton) view).setImageDrawable(getResources().getDrawable(R.drawable.stop,
                        null));
            }
        }
        } );
    }

//    @Override
//    protected void onStart() {
//        startService(new Intent(MainActivity.this, MusicService.class));
//        super.onStart();
//    }
}